package top.baselitch.bannerholder;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import top.baselitch.widget.bannerholder.BannerClickListenenr;
import top.baselitch.widget.bannerholder.BannerHolderView;
import top.baselitch.widget.bannerholder.HolderAttr;

public class MainActivity extends AppCompatActivity implements BannerClickListenenr {
    private List<Bitmap> mpas;
    private BannerHolderView holder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        holder = (BannerHolderView) findViewById(R.id.banner_holder);
        HolderAttr.Builder builder = holder.getHolerAttr();
        builder.setSwitchDuration(900)//设置切换Banner的持续时间
                .setBannerClickListenenr(this)//
                .setAutoLooper(true)//设置
                .setLooperTime(1000)
                .setIndicatorResId(R.drawable.banner_holder_selector)
                .setBackgroup(true)
                .setBannerClickListenenr(new BannerClickListenenr() {
                    @Override
                    public void onBannerClick(int p) {
                        //p: 页面索引
                    }
                });
        holder.setHolerAttr(builder);
        holder.setHolderBitmaps(getDatas());
    }

    /**
     * 获取图片集合
     * @return
     */
    public List<Bitmap> getDatas(){
        List<Bitmap> mpas = new ArrayList<>();
        Bitmap b2 = BitmapFactory.decodeResource(getResources(),R.drawable.img_mybg);
        Bitmap b3 = BitmapFactory.decodeResource(getResources(),R.drawable.def_ba);
        mpas.add(b2);
        mpas.add(b3);
        mpas.add(b2);
        mpas.add(b3);
        mpas.add(b2);
        return mpas;
    }

    @Override
    public void onBannerClick(int p) {
    }
}
